﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using University.Workshop.Presenters;
using University.Workshop.Model;

namespace University.Workshop.WinApp
{
    public partial class FormMainGifts : Form,IGifts
    {
        public PresenterGifts presenter;
        #region Interface Members 
        public string NameGift
        {
            get
            {
                return giftNameAdd.Text.ToUpper();
            }
            set
            {
                giftNameAdd.Text = value;
            }
        }

        public string PriceGift
        {
            get
            {
                return giftPrice.Text;
            }
            set
            {
                giftPrice.Text = value;
            }
        }

        public DataTable TableGifts
        {
            get
            {
                return (DataTable)dataGridGifts.DataSource;
            }
            set
            {
                dataGridGifts.DataSource = value;
            }
        }
        public string NameGiftFromTable
        {
            get
            {
                if (dataGridGifts.SelectedCells.Count == 0)
                {
                    throw new BusinessException("Porfavor seleccione un proveedor para Realizar la operacion");
                }
                
                return dataGridGifts.CurrentRow.Cells[0].Value.ToString();
            }

        }
        #endregion

        public FormMainGifts()
        {
            InitializeComponent();
            presenter = new PresenterGifts(this);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                presenter.AddGift();

            }
            catch(Exception ex) {
                MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK,
                                     MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1,
                                     MessageBoxOptions.RightAlign);
            }
        }
       

        private void button4_Click(object sender, EventArgs e)
        {
            PresenterGifts.GenerateReport();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void FormMainGifts_Load(object sender, EventArgs e)
        {
            try
            {
                presenter.ChargeDataTable();
            }
            catch (Exception ex) {
                MessageBox.Show(this, ex.Message, "Error Al Cargar", MessageBoxButtons.OK,
                       MessageBoxIcon.Error, MessageBoxDefaultButton.Button1,
                       MessageBoxOptions.RightAlign);
            }
        }

        private void deleteGift_Click(object sender, EventArgs e)
        {
            presenter.DeleteGift();

        }
    }
}
